//
//  SKUDetailWatchScrView.m
//  ZITHER
//
//  Created by weixin on 2018/8/16.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDetailWatchScrView.h"

@implementation SKUDetailWatchScrView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.delegate = self;
        self.bounces = NO;
        self.showsHorizontalScrollIndicator = NO;
        self.contentSize = CGSizeMake(0, 1300);
        [self setUI];
    }
    return self;
}


-(void)setUI{
    
    [self addSubview:self.TopscroView];
    
    [self addSubview:self.TopscroView.pageController];
    
    [self addSubview:self.UserImageS];
    
    [self addSubview:self.ScrPublicV];
    
    [self addSubview:self.GraphV];
    
    self.UserImageS.frame = CGRectMake(0, CGRectGetMaxY(self.TopscroView.frame)+20, kScreenW, 200);
    self.ScrPublicV.frame = CGRectMake(15, CGRectGetMaxY(self.UserImageS.frame)+60, kScreenW-30, 280);
    self.GraphV.frame = CGRectMake(0, CGRectGetMaxY(self.ScrPublicV.frame), kScreenW, 600);
    
    
    
    
    
//    [RACObserve (self,ScrPublicV.labSubtitle.text) subscribeNext:^(id x){
//        NSString *str = x;
//        NSLog(@"%@",str);
//        //        NSValue *value = x;
//        //        CGRect frame =  [value CGRectValue];
//        //        NSLog(@"CGRectGetMaxY(frame) -------------- %f",CGRectGetMaxY(frame));
//        //
//        //        CGFloat height = [NSString textHeight:v1.labSubtitle.text font:15 width:self.ScrPublicV.labSubtitle.frame.size.width];
//        //        NSLog(@"height -------------- %f",height);
//
//        self.contentSize = CGSizeMake(0, CGRectGetMaxY(self.ScrPublicV.frame)+600);
//    }];
    

//    [self.UserImageS mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.TopscroView.mas_bottom).offset(80);
//        make.left.equalTo(self.mas_left).offset(0);
//        make.width.mas_equalTo(kScreenW);
//        make.height.mas_equalTo(200);
//    }];
    
    

   
//    [self.ScrPublicV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.UserImageS.mas_bottom).offset(60);
//        make.left.equalTo(self.mas_left).offset(15);
//        make.width.mas_equalTo(kScreenW-30);
//        make.height.mas_equalTo(280);
//    }];
    
    

    
    
//    [self.GraphV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.ScrPublicV.mas_bottom).offset(0);
//        make.left.equalTo(self.mas_left).offset(0);
//        make.width.mas_equalTo(kScreenW);
//        make.height.mas_equalTo(600);
//    }];
    


    
    
//    [RACObserve (self.GraphV,frame) subscribeNext:^(id x){
//        NSValue *value = x;
//        CGRect frame =  [value CGRectValue];
//        NSLog(@"CGRectGetMaxY(frame) -------------- %f",CGRectGetMaxY(frame));
//
//        CGFloat height = [NSString textHeight:self.ScrPublicV.labSubtitle.text font:15 width:self.ScrPublicV.labSubtitle.frame.size.width];
//        NSLog(@"height -------------- %f",height);
//
//        self.contentSize = CGSizeMake(0, CGRectGetMaxY(frame)+height);
//    }];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    /* TODO: ================= 把导航栏向上顶 =================*/

//    if (scrollView.contentOffset.y < kTopBarSafeHeight+120) {
//        //如果快到底部或者快到顶部 10 距离直接给个动画
//        //其他时候正常跟随
//        SKUDetailVC * vc = (SKUDetailVC*)[self getViewController:[SKUDetailVC class]];
//
//        CGRect frame = vc.NavView.frame;
//        CGRect frameTitle = vc.viewTitle.frame;
//        frameTitle.origin.y = 120 - scrollView.contentOffset.y;
//        frame.origin.y = 0 - scrollView.contentOffset.y;
//
//        NSLog(@"scrollView.contentOffset.y == %f",scrollView.contentOffset.y);
//        NSLog(@"frameTitle.origin.y == %f",frameTitle.origin.y);
//        NSLog(@"frame.origin.y == %f",frame.origin.y);
//
//        vc.NavView.frame = frame;
//        vc.viewTitle.frame = frameTitle;
//
//    }else{
//
//        SKUDetailVC * vc = (SKUDetailVC*)[self getViewController:[SKUDetailVC class]];
//        CGRect frame = vc.NavView.frame;
//        CGRect frameTitle = vc.viewTitle.frame;
//        if (scrollView.contentOffset.y>kTopBarSafeHeight+160-10) {
//            frameTitle.origin.y  = 20;
//            frame.origin.y = -120-kTopBarSafeHeight;
//            vc.NavView.frame = frame;
//            vc.viewTitle.frame = frameTitle;
//        }else if (scrollView.contentOffset.y<10){
//            frameTitle.origin.y  = 120+kTopBarSafeHeight;
//            frame.origin.y = +kTopBarSafeHeight;
//            vc.NavView.frame = frame;
//            vc.viewTitle.frame = frameTitle;
//
//        }
//    }
//
    
}




-(MainDetailTopScrollView *)TopscroView{
    if (!_TopscroView) {
        _TopscroView = [[MainDetailTopScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
        //        _TopscroView.backgroundColor = [UIColor redColor];
    }
    return _TopscroView;
}

-(SKUDefultScrUserImageS *)UserImageS{
    if (!_UserImageS) {
        _UserImageS = [[SKUDefultScrUserImageS alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 200)];
    }
    return _UserImageS;
}

-(SKUDefultScrPublicV *)ScrPublicV{
    if (!_ScrPublicV) {
        _ScrPublicV = [[SKUDefultScrPublicV alloc]initWithFrame:CGRectMake(15, 0, kScreenW-30, 200)];
    }
    return _ScrPublicV;
}

-(SKUDefultGraphV *)GraphV{
    if (!_GraphV) {
        _GraphV = [[SKUDefultGraphV alloc]initWithFrame:CGRectMake(0,500, kScreenW, 700)];
        [_GraphV setBlockUpLoadData:^{
            if (self.blockUpLoadData) {
                self.blockUpLoadData();
            }
        }];
    }
    return _GraphV;
}


@end
